#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <sstream>
using namespace std;
struct Node {
	int bf = 0;
	string val;
	Node* left = nullptr;
	Node* right = nullptr;
	Node* parent = nullptr;
};
string sp;
Node* H = nullptr;
void getTree(Node*& h)
{
	h = new Node;
	queue<Node*> q;
	string line;
	getline(cin, line);
	stringstream ss(line);
	ss >> h->val;
	q.push(h);
	while (q.size()) {
		Node* cur = q.front(); q.pop();
		string l, r;
		if (!(ss >> l))break;
		if (l != sp) {
			cur->left = new Node;
			cur->left->val = l;
			cur->left->parent = cur;
			q.push(cur->left);
		}
		if (!(ss >> r))break;
		if (r != sp) {
			cur->right = new Node;
			cur->right->val = r;
			cur->right->parent = cur;
			q.push(cur->right);
		}
	}
}
bool j = false;
void in(Node* h)
{
	if (!h) return;
	in(h->left);
	if (j) cout << ',';
	cout << h->val; j = true;
	in(h->right);
}
Node* nextNode(Node* c)
{
	if (c == nullptr) return c;
	if (c->right) {
		c = c->right;
		while (c->left) c = c->left;
		return c;
	}
	while (c->parent && c->parent->right == c) c = c->parent;
	return c->parent;
}

bool jugbst(Node* h)
{
	if (!h) return true;
	Node* cur = h, *next = nullptr;
	while (cur->left) cur = cur->left;
	while (next = nextNode(cur)) {
		if (next->val < cur->val) {
			return false;
		}
		cur = next;
	}
	return true;
}

int main()
{
	cin >> sp; (void)getchar();
	getTree(H);
	in(H); cout << endl;
	if (jugbst(H)) cout << "true";
	else cout << "false";
	
    return 0;
}
